﻿using Obtics.Collections;

#if TVDP_UNITTESTING
using TvdP.UnitTesting;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif


using System.Collections.Generic;
using System;
using Obtics.Values;
using System.Collections;
using System.Linq;

namespace ObticsUnitTest.Obtics.Collections
{
    
    
    /// <summary>
    ///This is a test class for ObservableEnumerableTest and is intended
    ///to contain all ObservableEnumerableTest Unit Tests
    ///</summary>
    public partial class ObservableEnumerableTest
    {
        [TestMethod]
        public void ThenByTest1()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1])
                ),
                "ThenByTest1(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, char>(s => s[1]);

            Assert.AreEqual(
                ObservableEnumerable.ThenBy(seq, sel),
                ObservableEnumerable.ThenBy(seq, sel),
                "ThenByTest1(b)"
            );
        }

        [TestMethod]
        public void ThenByTest2()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]))
                ),
                "ThenByTest2(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));

            Assert.AreEqual(
                ObservableEnumerable.ThenBy(seq, sel),
                ObservableEnumerable.ThenBy(seq, sel),
                "ThenByTest2(b)"
            );
        }

        [TestMethod]
        public void ThenByTest3()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1], Comparer<char>.Default)
                ),
                "ThenByTest3(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, char>(s => s[1]);
            var comp = Comparer<char>.Default;

            Assert.AreEqual(
                ObservableEnumerable.ThenBy(seq, sel, comp),
                ObservableEnumerable.ThenBy(seq, sel, comp),
                "ThenByTest3(b)"
            );
        }

        [TestMethod]
        public void ThenByTest4()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]), Comparer<char>.Default)
                ),
                "ThenByTest4(a)"
            );

            var seq = ObservableEnumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));
            var comp = Comparer<char>.Default;

            Assert.AreEqual(
                ObservableEnumerable.ThenBy(seq, sel, comp),
                ObservableEnumerable.ThenBy(seq, sel, comp),
                "ThenByTest4(b)"
            );
        }

        [TestMethod]
        public void ThenByTest5()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1])
                ),
                "ThenByTest5(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, char>(s => s[1]);

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenBy(seq, sel),
            //    ObservableEnumerable.ThenBy(seq, sel),
            //    "ThenByTest5(b)"
            //);
        }

        [TestMethod]
        public void ThenByTest6()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]))
                ),
                "ThenByTest6(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenBy(seq, sel),
            //    ObservableEnumerable.ThenBy(seq, sel),
            //    "ThenByTest6(b)"
            //);
        }

        [TestMethod]
        public void ThenByTest7()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => s[1], Comparer<char>.Default)
                ),
                "ThenByTest7(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, char>(s => s[1]);
            //var comp = Comparer<char>.Default;

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenBy(seq, sel, comp),
            //    ObservableEnumerable.ThenBy(seq, sel, comp),
            //    "ThenByTest7(b)"
            //);
        }

        [TestMethod]
        public void ThenByTest8()
        {
            Assert.IsTrue(
                System.Linq.Enumerable.SequenceEqual(
                    new string[] { "AA", "AB", "BA", "BB" },
                    ObservableEnumerable.ThenBy(System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]), s => ValueProvider.Static(s[1]), Comparer<char>.Default)
                ),
                "ThenByTest8(a)"
            );

            // does not hold when source is not an IObservableOrderedEnumerable as generated by
            // the Obtics methods.
            //
            //var seq = System.Linq.Enumerable.OrderBy(new string[] { "BA", "BB", "AB", "AA" }, s => s[0]);
            //var sel = new Func<string, IValueProvider<char>>(s => ValueProvider.Static(s[1]));
            //var comp = Comparer<char>.Default;

            //Assert.AreEqual(
            //    ObservableEnumerable.ThenBy(seq, sel, comp),
            //    ObservableEnumerable.ThenBy(seq, sel, comp),
            //    "ThenByTest8(b)"
            //);
        }
    
    }
}
